package main

import (
	"fmt"
)

const (
	first = iota
	second
	third
)

func main() {
	// fmt.Println(first)
	// fmt.Println(second)
	// fmt.Println(third)
	// myArray := [...]int{3, 2, 1, 5}
	// mySlice := myArray[:2]
	// fmt.Println(len(myArray))
	// fmt.Println(mySlice)

	// mySlice := make([]float32, 10)
	// fmt.Println(mySlice)
	//
	// myMap := make(map[int]string, 10)
	// fmt.Println(myMap)
	//
	// add := 1 + 2
	// println(add)
	// remainder := 5 / 2
	// println(remainder)

	// if foo := 2; foo == 1 {
	// 	println("true")
	// } else {
	// 	fmt.Println("fasle")
	// }
	//
	// switch fo := 1; fo {
	// case 1:
	// 	println("is 1")
	// case 2:
	// 	println("is 2")
	//
	// }

	// for i := 0; i < 5; i++ {
	// 	println(i)
	// }

	// i := 0
	// for {
	// 	i++
	// 	println(i)
	// 	if i > 5 {
	// 		break
	// 	}
	// }
	// s := []string{"foo", "bar", "buz"}
	// for idx, v := range s {
	// 	println(idx, v)
	// }

	// m := make(map[string]string)
	// m["first"] = "abc"
	// m["second"] = "sec"
	// m["third"] = "thir"
	// for k, v := range m {
	// 	println(k, v)
	// }
	//
	// var option string
	// fmt.Scanln(&option)
	// println(option)
	// message := "hello message"
	// sayHello(&message)
	// println(message)

	foo := myStruct{"bar"}
	// foo.myField = "bar"
	fmt.Println(foo)

	foo2 := newMyStruct2()
	// foo2.myMap = map[string]string
	foo2.myMap["bar"] = "barvalue"
	fmt.Println(foo2)

	mp := messagePrinter{"offfff"}
	mp.printMessage()
	mp.setMessage("message 90ad")
	fmt.Println(mp)

	emp := enhanceMessagePrinter{messagePrinter{"sfdfdd"}}
	// emp := enhanceMessagePrinter{}
	// emp.messagePrinter.message = "sdewef"
	// emp.message = "sdfsdwe"
	emp.printMessage()

	ch := make(chan string)
	doneCh := make(chan bool)
	go abcGen(ch)
	go printer(ch, doneCh)
	println("this is from main")
	// time.Sleep(100 * time.Millisecond)
	<-doneCh
}
func abcGen(ch chan string) {
	for l := byte('a'); l <= byte('z'); l++ {
		ch <- string(l)
	}
	close(ch)
}
func printer(ch chan string, doneCh chan bool) {
	for l := range ch {
		println(l)
	}
	doneCh <- true
}

type messagePrinter struct {
	message string
}
type enhanceMessagePrinter struct {
	messagePrinter
}

func (mp *messagePrinter) printMessage() {
	println(mp.message)
}
func (mp *messagePrinter) setMessage(message string) {
	mp.message = message
	println(mp.message)
}

type myStruct2 struct {
	myMap map[string]string
}
type myStruct struct {
	myField string
}

func newMyStruct2() *myStruct2 {
	result := myStruct2{}
	result.myMap = map[string]string{}
	return &result
}
func sayHello(message *string) {
	fmt.Println(message)
	*message = "hello gooooo"
}
func add(terms ...int) int {
	result := 0
	for _, term := range terms {
		result += term
	}
	return result
}

func init() {
	const (
		mm = 1
	)
	println("init---")
}
